//角色管理模块的接口
import request from "../../../utils/request.ts";
import {T_MenuResponseData, T_RoleData, T_RoleResponseData} from "./type.ts";

enum API {
    //获取全部职位的接口
    ALLROLE_URL = "/admin/acl/role/",
    //新增职位
    ADDROLE_URL = "/admin/acl/role/save",
    //更新已有的职位
    UPDATEROLE_URL = "/admin/acl/role/update",
    //获取全部菜单与按钮的数据
    ALLPERMISSION_URL = "/admin/acl/permission/toAssign/",
    //给角色职位分配权限
    SERPERMISSION_URL = "/admin/acl/permission/doAssign/?",
    //删除职位
    REMOVEROLE_URL = "/admin/acl/role/remove/"
}


//获取全部的角色
export const reqAllRoleList = (page: number, limit: number, rolekw: string) => request.get<any, T_RoleResponseData>(API.ALLROLE_URL + `${page}/${limit}?roleName=${rolekw}`);


//添加/更新职位
export const reqAddOrUpdateRole = (data: T_RoleData) => {
    if (data.id) {
        //更新职位
        return request.put<any, any>(API.UPDATEROLE_URL, data);
    } else {
        //添加职位
        return request.post<any, any>(API.ADDROLE_URL, data);
    }
}

//根据id获取全部菜单与按钮的数据
export const reqAllMenuList = (roleId: number) => request.get<any, T_MenuResponseData>(API.ALLPERMISSION_URL + roleId)

//根据id响应的职位下发权限
export const reqSetPermission = (roleId: number, permissionIds: number[]) => request.post<any, any>(API.SERPERMISSION_URL + `roleId=${roleId}&permissionId=${permissionIds}`);

//根据id删除已有职位
export const reqRemoveRole = (roleId: number) => request.delete<any, any>(API.REMOVEROLE_URL + roleId);



